Welcome to my blog

How to create an alias in a Unix shell

This is generally the same for most shells, and will work on almost any Unix based OS like GNU/Linux or MacOS. * The syntax to create a new alias is \

alias <alias_name>=”command” 

so for example, I’ve shortend my package installation from doas pacman -S to simply get by typing \

alias get="doas pacman -S" 

into the terminal. The problem with this is that it only lasts that session, so for any alias you want to last, the command must be run every time you launch the your shell. Different emulators have different files for this (to see hidden files (those starting with a dot(yes I use nested brackets)) open your file manager and press ctrl + h):

Put the line source ~/.aliases at the end of the file, now you can create a file in your home directory called .aliases and in there put all the alias commands. My .aliases looks like this (the # makes the rest of that line a comment):

alias get="doas pacman -S"
alias rem="doas pacman -R"
alias REM="doas pacman -Rns"
alias up="doas pacman -Syu"
alias clean="pacman -Qdtq | doas pacman -Rs -"
alias aur="paru -S"
alias rua="paru -R" # aur backwards
alias aup="paru -Sua" # aup = aur + up

alias hash="sha256sum"
alias addkey="gpg --keyserver keys.gnupg.net --recv-keys"
alias grup="doas grub-mkconfig -o /boot/grub/grub.cfg" # grup = grub + up (as in update)
alias vmm="doas systemctl start libvirtd && doas virsh net-start default"

By Alex Gorichev